package com.xr.hr.clock;

import com.bstek.dorado.common.*;
import com.bstek.dorado.data.*;
import com.bstek.dorado.data.db.DBStatement;
import com.bstek.dorado.view.*;
import com.bstek.dorado.view.data.*;
import com.bstek.dorado.view.control.*;
import com.xr.common.CommUtil;

/**
 * wsrMbManageViewModel
 */
public class wsrMbManageViewModel extends DefaultViewModel {
  protected void doUpdateData(ParameterSet parameters, ParameterSet outParameters)
      throws Exception {
	  DBStatement dbs = new DBStatement();
	  Dataset dsm=getDataset("datasetMb");
	  Dataset dsd=getDataset("datasetDeal");
	  String sqlMb="";
	  String dw="",qianhou="",how="";
	  
	  how=dsd.getString("HOW");
	  switch (dsd.getInt("DATE")){
	  case 1: dw="/(24*60)";break;
	  case 2: dw="/(24)";break;
	  case 3: dw="/1";break;
	  //case 4: 
	  };
	  
	  switch (dsd.getInt("QIANHOU")){
	  case -1: qianhou="-";break;
	  case 1: qianhou="+";break;
	  };
	 // System.out.println("==========="+dsd.getInt("FIELD"));
	  switch (dsd.getInt("FIELD")){
	  case 0: 
		  if(dsd.getInt("DATE")==4){
			  sqlMb="onduty_time=add_months(onduty_time,"+qianhou+how+"),offduty_time=add_months(offduty_time,"+qianhou+how+") ";
		  }else{
			  sqlMb="onduty_time=onduty_time"+qianhou+how+dw+",offduty_time=offduty_time"+qianhou+how+dw;
		  }
		  break;
	  case 1: 
		  if(dsd.getInt("DATE")==4){
			  sqlMb="onduty_time=add_months(onduty_time,"+qianhou+how+") ";
		  }else{
			  sqlMb="onduty_time=onduty_time"+qianhou+how+dw;
		  }
		  break;
	  case 2: 
		  if(dsd.getInt("DATE")==4){
			  sqlMb="offduty_time=add_months(offduty_time,"+qianhou+how+") ";
		  }else{
			  sqlMb="offduty_time=offduty_time"+qianhou+how+dw;
		  }
		  break;
	  };
	  dbs.setSql("update cw_wsr_mb_item set "+sqlMb+" where WSR_MB_ID="+dsm.getString("WSR_MB_ID"));
	  dbs.execute(); 
	  dbs.close();
   // super.doUpdateData(parameters, outParameters);
  }
  public void mb_submit(ParameterSet parameters, ParameterSet outParameters)
  throws Exception {
	  DBStatement dbs = new DBStatement();
	  Dataset ds=getDataset("datasetMb");
	  CommUtil.dbsUpdateData(dbs, ds, "CW_WSR_MB", "WSR_MB_ID","seq_cw_wsr");
	  dbs.close();
  }
  public void MbItem_submit(ParameterSet parameters, ParameterSet outParameters)
  throws Exception {
	  DBStatement dbs = new DBStatement();
	  Dataset ds=getDataset("datasetMbItem");
	  CommUtil.dbsUpdateData(dbs, ds, "CW_WSR_MB_ITEM", "WSR_MB_ITEM_ID","seq_cw_wsr");
	  dbs.close();
  }
 
  public void delMb(ParameterSet parameters, ParameterSet outParameters)
  throws Exception {
	  DBStatement dbs = new DBStatement();
	  Dataset dsm=getDataset("datasetMb");
	  dbs.setSql("delete from cw_wsr_mb_item where wsr_mb_id="+dsm.getString("wsr_mb_id"));
	  dbs.execute();
	  dbs.setSql("delete from cw_wsr_mb where wsr_mb_id="+dsm.getString("wsr_mb_id"));
	  dbs.execute();
	  dbs.close();
  }
}
